<%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false"
         pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>学生信息</title>
    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <!-- web路径：此处的${APP_PATH}无法使用 待解决
    不以/开始的相对路径，找资源，以当前资源的路径为基准，经常容易出问题。
    以/开始的相对路径，找资源，以服务器的路径为标准(http://localhost:3306)；需要加上项目名
		http://localhost:3306/crud
    -->

    <script type="text/javascript" src="${APP_PATH}/static/js/jquery-1.12.4.min.js"></script>

    <link href="${APP_PATH}/static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="${APP_PATH}/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</head>
<body>
<%-- ng-app="myApp" 搭建页面 ng-controller="stuController"--%>
<div class="container"  >
    <div >
    <%-- 标题 --%>
    <div class="row">
        <div class="col-md-12">
            <h1>学生信息管理</h1>
        </div>
    </div>
    <%-- 按钮 --%>
    <div class="row" >
        <form action="${APP_PATH}/stu/saveStuInfo" enctype="multipart/form-data"  method="post">
        <div class="col-md-4 col-md-offset-8">
            <input type="file" id="file" name="file" />
<%--            <button id="addStuInfoBtn" class="btn btn-primary">导入数据</button>--%>
            <input type="submit">
        </div>
        </form>
    </div>
    <%-- 数据表格 --%>
    <div class="row" >
        <div class="col-md-12">

            <table class="table table-hover">
                <tr>
                    <th>#</th>
                    <th>学生姓名</th>
                    <th>性别</th>
                    <th>邮箱</th>
                    <th>所在学校</th>
                    <th>操作</th>
                </tr>

                <c:forEach items="${stuList.list}" var="stu">
                <form action="${APP_PATH}/stu/addStuInfoByExcel" method="post">
                        <tr >
                            <th id="stuId" >
                                <input name="studentId" value="${stu.studentId}">
                            </th>
                            <th id="stuName">
                                <input name="studentName" value="${stu.studentName}">
                            </th>
                            <th id="stuSex">
                                <input name="studentSex" value="${stu.studentSex=="m"?"男":"女"}" >
                            </th>
                            <th id="stuEmail">
                                <input name="studentEmail" value="${stu.studentEmail}">
                            </th>
                            <th id="stuSchoolName" >
                                <input name="schoolName" value="${stu.school.schoolName}">
                            </th>
                            <th hidden="hidden" id="schoolId">
                                <input name="schoolId" value="${stu.school.schoolId}">
                            </th>
                            <th>
                                <button class="btn btn-primary btn-sm">
                                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                                    编辑
                                </button>
                                <button class="btn btn-danger btn-sm">
                                    <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
                                    删除
                                </button>
                                <button id="downloadInfoBtn" type="submit" class="btn btn-success btn-sm">
                                    <span class="glyphicon glyphicon-save" aria-hidden="true"></span>
                                    导出
                                </button>
                            </th>
                        </tr>
                </form>
                </c:forEach>

            </table>

        </div>
    </div>
    <%-- 分页信息 --%>
    <div class="row">
        <!-- 分页文字信息 -->
        <div class="col-md-6">
            当前第${stuList.pageNum}页,总共${stuList.pages}页,总共${stuList.total}记录
        </div>
        <!--分页条-->
        <div class="col-md-6">
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    <li><a href="${APP_PATH}/stu/queryAll?pn=1">首页</a></li>
                    <c:if test="${stuList.hasPreviousPage}">
                        <li>
                            <a href="${APP_PATH}/stu/queryAll?pn=${stuList.pageNum-1}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                    </c:if>
                    <c:forEach items="${stuList.navigatepageNums}" var="page_Num">
                        <c:if test="${page_Num == stuList.pageNum}">
                            <li class="active"><a href="#">${page_Num}</a></li>
                        </c:if>

                        <c:if test="${page_Num != stuList.pageNum}">
                            <li ><a href="${APP_PATH}/stu/queryAll?pn=${page_Num}">${page_Num}</a></li>
                        </c:if>

                    </c:forEach>
                    <c:if test="${stuList.hasNextPage}">
                        <li>
                            <a href="${APP_PATH}/stu/queryAll?pn=${stuList.pageNum+1}" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </c:if>
                    <li><a href="${APP_PATH}/stu/queryAll?pn=${stuList.pages}">末页</a></li>
                </ul>
            </nav>
        </div>
    </div>
    </div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/angular.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/app.js"></script>
<script type="text/javascript">
    $(document).on("click", "#downloadInfoBtn", function () {
        var stuId = $(this).parents("tr").find("#stuId").text();
        $.ajax({
        })
    })
</script>
</body>
</html>
